//
//  BasNavViewController.swift
//  sinaweibowj
//
//  Created by Macintosh on 15/12/23.
//  Copyright © 2015年 mactoinsh. All rights reserved.
//

import UIKit

class BasNavViewController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //设置返回手势代理
        self.interactivePopGestureRecognizer?.delegate = self
        // Do any additional setup after loading the view.
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        //自定义返回按钮  导航控制器的返回手势协议会被重置
        if self.childViewControllers.count != 0{
        let btn = UIButton(title: "返回", backgroundImage:nil , fontSize: 14, color: UIColor.lightGrayColor(), imageName: "navigationbar_back_withtext")
        btn.addTarget(self , action: "back", forControlEvents: .TouchUpInside)
        
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn )
        
        //隐藏BottomBar按钮，要在push上一个控制器修改 push后一个控制器的属性
        viewController.hidesBottomBarWhenPushed = true
        }
        //调用分类的跳转函数
        super.pushViewController(viewController, animated: true)
    }
    
    
    @objc private func back() {
        
        self.popViewControllerAnimated(true)
        
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool{
        
        print("你若安好便是晴天")
        return self.childViewControllers.count != 1
    }
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
